#define _CRT_SECURE_NO_WARNINGS 1

void sum_diff(float op1, float op2, float* psum, float* pdiff)
{
    *psum = op1 + op2;
    *pdiff = op1 - op2;
}

void findmax(int* px, int* py, int* pmax)
{
    if (*px > *py)
        *pmax = *px;
    else
        *pmax = *py;
}

int search(int list[], int n, int x)
{
    for (int i = 0; i < n; i++)
    {
        if (list[i] == x)
            return i;
    }
    return -1;
}

void sort(int a[], int n)
{
	int i, j;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (a[j] > a[j + 1])
			{
				int tmp;
				tmp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = tmp;
			}
		}
	}
}

void ArrayShift(int a[], int n, int m)
{
    int* b = (int*)malloc(sizeof(int) * n);
    int j;
    for (int i = 0; i < n; i++)
    {
        j = (i + m) % n;
        b[j] = a[i];
    }
    for (int i = 0; i < n; i++)
    {
        a[i] = b[i];
    }
}

void strmcpy(char* t, int m, char* s)
{
    int i = 0, j = 0;
    while (t[i] != '\0')
    {
        i++;
    }
    if (i + 1 > m)
    {
        t = t + m - 1;
        while (*t != '\0')
        {
            *s = *t;
            s++;
            t++;
        }
        *s = '\0';
    }
    else
        *s = '\0';
}

void StringCount(char* s)
{
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    while (*s != '\0')
    {
        if (*s >= 'A' && *s <= 'Z')
            a++;
        else if (*s >= 'a' && *s <= 'z')
            b++;
        else if (*s == ' ')
            c++;
        else if (*s >= '0' && *s <= '9')
            d++;
        else
            e++;
        s++;
    }
    printf("%d %d %d %d %d", a, b, c, d, e);
}

void delchar(char* str, char c)
{
    char* ps = str;
    while (*ps != '\0')
    {
        if (*ps == c)
            ps++;
        else
        {
            *str = *ps;
            str++;
            ps++;
        }
    }
    *str = '\0';
}

char* str_cat(char* s, char* t)
{
    char* root = s;
    while (*s != '\0')
    {
        s++;
    }
    while (*t != '\0')
    {
        *s = *t;
        s++; t++;
    }
    *s = '\0';
    return root;
}

void fun(char* s)
{
    while (*s != '\0')
    {
        if (*s >= '0' && *s <= '9')
            *s = '#';
        s++;
    }
}

char* match(char* s, char ch)
{
    while (*s != '\0')
    {
        if (*s == ch)
            return s;
        s++;
    }
    return NULL;
}

double getScore(int* score, int total)
{
    int max = score[0];
    int min = score[0];
    int sum = 0, i = 0;
    for (i = 0; i < total; i++)
    {
        sum += score[i];
        if (max < score[i])
            max = score[i];
        if (min > score[i])
            min = score[i];
    }
    return (sum - max - min) * 1.0 / (total - 2);
}

